package cn.biplam.common.file.importfile.sheet;

import org.apache.poi.hssf.usermodel.HSSFSheet;

import cn.biplam.common.client.Log;
import cn.biplam.common.client.Log.Log_Level;
import cn.biplam.common.file.ExcelFile;
import cn.biplam.common.file.importfile.ExcelFileSheet;
import cn.biplam.common.wrapper.ErrorMessage;
import cn.biplam.common.wrapper.KvMap;

/**
 * sheet中的表信息对象
 * @author WangSong 2009-7-28下午04:15:01
 * @version 1.0
 */
public class TableSheet {
	
	/** 表信息<列属性名,列属性值>*/
	private KvMap<String,String> table;
	
	/**
	 * 构造函数
	 * @param sheet sheet对象
	 * @throws ErrorMessage
	 */
	public TableSheet(HSSFSheet sheet) throws ErrorMessage{
		table = new KvMap<String, String>();
		init(sheet);
	}
	
	/**
	 * 初始化表信息
	 * @param sheet sheet对象
	 * @throws ErrorMessage
	 */
	private void init(HSSFSheet sheet) throws ErrorMessage{
		if(sheet!=null && sheet.getPhysicalNumberOfRows()>=3){
			/** 取表信息*/
			String tableName = ExcelFile.getCellContent(sheet,0,1);
			String tableCName = ExcelFile.getCellContent(sheet,1,1);
			String tableComent = ExcelFile.getCellContent(sheet,2,1);
			
			table.put(ExcelFileSheet.Name.TableName.toString(), tableName);
			table.put(ExcelFileSheet.Name.TableCName.toString(), tableCName);
			table.put(ExcelFileSheet.Name.TableComment.toString(), tableComent);
		}else{
			Log.write(new ErrorMessage("sheet is not found legal table info"),Log_Level.Warnning);
		}
	}
	
	/**
	 * 取表名
	 * @return 表名
	 */
	public String getTableName(){
		return table.getByKey(ExcelFileSheet.Name.TableName.toString());
	}
	
	/**
	 * 取表中文名
	 * @return 表中文名
	 */
	public String getTableCName(){
		return table.getByKey(ExcelFileSheet.Name.TableCName.toString());
	}
	
	/**
	 * 取表说明
	 * @return 表说明
	 */
	public String getTableComment(){
		return table.getByKey(ExcelFileSheet.Name.TableComment.toString());
	}
	
}
